package com.gxuwz.restaurant.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxuwz.restaurant.common.Result;
import com.gxuwz.restaurant.entity.SeatManage;
import com.gxuwz.restaurant.mapper.SeatManageMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/cleaner")
public class CleanerController {

    @Resource
    SeatManageMapper seatManageMapper;
    String cleanerName;
    @GetMapping("/showSeat")   //get用来查询
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String search,
                              @RequestParam String cleanerName) {

this.cleanerName=cleanerName;
        LambdaQueryWrapper<SeatManage> wrapper = Wrappers.<SeatManage>lambdaQuery();
        if (StrUtil.isNotBlank(search)) {
            wrapper.like(SeatManage::getSeatNumber, search);
        }

          wrapper.eq(SeatManage::getCleanstate,"需要打扫");
        Page<SeatManage> Page = seatManageMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);


        return Result.success(Page);
    }

    @PutMapping("/handle/{id}")//put用来更新
    public Result<?> handle(@PathVariable int id) {

        SeatManage seatManage = new SeatManage();
        seatManage.setId(id);
        seatManage.setCleanstate("打扫完成");
        seatManage.setSeatState("true");
        seatManage.setCleanerName(this.cleanerName);
        seatManageMapper.updateById(seatManage);
        return Result.success();
    }
}
